package com.ruoyi.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.bo.KfnWorkOrderStorePandoraBo;
import com.ruoyi.system.domain.vo.KfnWorkOrderStorePandoraVo;
import com.ruoyi.system.service.IKfnWorkOrderStorePandoraService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 潘多拉店铺
 *
 * @author Panda
 * @date 2024-01-05
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/workOrderStorePandora")
public class KfnWorkOrderStorePandoraController extends BaseController {

    private final IKfnWorkOrderStorePandoraService iKfnWorkOrderStorePandoraService;

    /**
     * 查询潘多拉店铺列表
     */
    @SaCheckPermission("system:workOrderStorePandora:list")
    @GetMapping("/list")
    public TableDataInfo<KfnWorkOrderStorePandoraVo> list(KfnWorkOrderStorePandoraBo bo, PageQuery pageQuery) {
        return iKfnWorkOrderStorePandoraService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出潘多拉店铺列表
     */
    @SaCheckPermission("system:workOrderStorePandora:export")
    @Log(title = "潘多拉店铺", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(KfnWorkOrderStorePandoraBo bo, HttpServletResponse response) {
        List<KfnWorkOrderStorePandoraVo> list = iKfnWorkOrderStorePandoraService.queryList(bo);
        ExcelUtil.exportExcel(list, "潘多拉店铺", KfnWorkOrderStorePandoraVo.class, response);
    }

    /**
     * 获取潘多拉店铺详细信息
     *
     * @param storeId 主键
     */
    @SaCheckPermission("system:workOrderStorePandora:query")
    @GetMapping("/{storeId}")
    public R<KfnWorkOrderStorePandoraVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long storeId) {
        return R.ok(iKfnWorkOrderStorePandoraService.queryById(storeId));
    }

    /**
     * 新增潘多拉店铺
     */
    @SaCheckPermission("system:workOrderStorePandora:add")
    @Log(title = "潘多拉店铺", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody KfnWorkOrderStorePandoraBo bo) {
        return toAjax(iKfnWorkOrderStorePandoraService.insertByBo(bo));
    }

    /**
     * 修改潘多拉店铺
     */
    @SaCheckPermission("system:workOrderStorePandora:edit")
    @Log(title = "潘多拉店铺", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody KfnWorkOrderStorePandoraBo bo) {
        return toAjax(iKfnWorkOrderStorePandoraService.updateByBo(bo));
    }

    /**
     * 删除潘多拉店铺
     *
     * @param storeIds 主键串
     */
    @SaCheckPermission("system:workOrderStorePandora:remove")
    @Log(title = "潘多拉店铺", businessType = BusinessType.DELETE)
    @DeleteMapping("/{storeIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] storeIds) {
        return toAjax(iKfnWorkOrderStorePandoraService.deleteWithValidByIds(Arrays.asList(storeIds), true));
    }
}
